package jblip.apps.clip.cmds;

import jblip.BlipClient;

public class Msg extends ClipCommand {
  
  @Override
  public int getRequiredArgsCount() {
    return 2;
  }
  
  @Override
  public int getMaximumArgsCount() {
    return Integer.MAX_VALUE;
  }
  
  @Override
  public void execute(BlipClient client, String[] args) {
    StringBuilder msg = new StringBuilder(160);

    msg.append(args[1]);
    for (int i = 2; i < args.length; i++) {
      msg.append(' ');
      msg.append(args[i]);
    }
    client.postMessage(msg.toString(), args[0]);
    if (client.getLastError() == null) {
      System.out.println("Message sent.");
    } else {
      System.out.println("ERROR: " + client.getLastError().toString());
    }
  }

  @Override
  public String getName() {
    return "msg";
  }

  @Override
  public String getUsageMessage() {
    return "<user name> <message>";
  }

}
